#ifndef __CONFIG_H
#define __CONFIG_H

#include <string.h>
#include <stdio.h>

#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>

#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/select.h>
#include <sys/time.h>
#include <pthread.h>
#include <semaphore.h>
#include <csignal>


#ifndef FD_SETSIZE
    #define FD_SETSIZE 256
#endif

#define BUFFER_SIZE (92)
#define PORT        (8080)
#define SERVER_ADDR ("192.168.59.75")

enum ClientMessageType
{
    CLIENT_NONE,
    CLIENT_MSG_CREATE_ROOM,
    CLIENT_MSG_JOIN_ROOM,
    CLIENT_MSG_EXIT_ROOM,
    CLIENT_MSG_AGREE,
    CLIENT_MSG_REFUSED,
    CLIENT_MSG_MOVE_CHESS,
    CLIENT_MSG_RESTART_GAME,
};

enum ServerMessageType
{
    SERVER_MSG_OPERA_FAILED,
    SERVER_MSG_OPERA_SUCCESS,
    SERVER_MSG_ID_DUPLICATE,
    SERVER_MSG_ID_NOT_EXIST,
    SERVER_MSG_ID_NAME,
    SERVER_MSG_OTHER_JOIN_ROOM,
    SERVER_MSG_OTHER_EXIT_ROOM,
    SERVER_MSG_OTHER_AGREE,
    SERVER_MSG_OTHER_REFUSED,
    SERVER_MSG_OTHER_MOVE_CHESS,
    SERVER_MSG_OTHER_RESTART_GAME,
};

typedef struct _Message {                 // NOLINT
    enum ClientMessageType cli_msg;       /*消息类型 即为MessageType中的值*/
    enum ServerMessageType srv_msg;       /*针对操作结果类型的消息，填充该字段*/
    struct sockaddr_in     send_addr;     /*发送者IP*/
    struct sockaddr_in     recv_addr;
    char                   send_name[20]; /*发送者名称*/
    char                   recv_name[20]; /*接收者名称*/
    int                    coord_x;
    int                    coord_y;
    int                    color;
} message_t;

typedef struct _Client {                // NOLINT
    char               user_name[20];   // 用户名
    struct sockaddr_in user_addr;        // 用户IP地址，选择IPV4
    int                sockfd;          // 当前用户套接字描述符
} client_t;

#endif
